package com.codermn.demo713;

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 * @author jxau_scf
 * @date 2021/7/13 - 19:23
 */
public class Pipedstream {
    public static void main(String args[]) throws IOException
    {
        byte aByteData1 = 123, aByteData2 = 111;
        PipedInputStream pis = new PipedInputStream();
        PipedOutputStream pos = new  PipedOutputStream(pis);
        System.out.println("PipedInputStream");
        try
        { //把一个字节的数据123写到pos所指的管道中去
            pos.write(aByteData1);
            pos.write(aByteData2);
            //pos.write((byte)-1);
            //从pis所指的管道中读取一个字节的数据
            System.out.println((byte)pis.read());
            System.out.println((byte)pis.read());
            //System.out.println("====="+(byte)pis.read());
        }
        finally
        {
            pis.close();
            pos.close();
        }
    }
}
